<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Users
 *
 * This model represents user authentication data. It operates the following tables:
 * - user account data,
 * - user profiles
 *
 * @package	Tank_auth
 * @author	Ilya Konyukhov (http://konyukhov.com/soft/)
 */
class Payment extends CI_Model
{
	private $table_name			= 'payment';			// payment table

	function __construct()
	{
		parent::__construct();

		$ci =& get_instance();
		$this->table_name			= $ci->config->item('db_table_prefix', 'tank_auth').$this->table_name;

	}

	/**
	 * Get user record by Id
	 *
	 * @param	int
	 * @param	bool
	 * @return	object
	 */
	function get_user_by_id($user_id)
	{
		$this->db->where('users_id', $user_id);
		$query = $this->db->get($this->table_name);
		if ($query->num_rows() == 1) return $query->row();
		return NULL;
	}


	function is_transaction_num_used($transaction_num)
	{
		$this->db->select('1', FALSE);
		$this->db->where('LOWER(transaction_num)=', strtolower($transaction_num));

		$query = $this->db->get($this->table_name);
		return $query->num_rows() == 0;

	}
	function user_has_transaction_num($users_id)
	{
		$this->db->select('users_id');
		$this->db->where('users_id', $users_id);

		$query = $this->db->get($this->table_name);

			if($query->num_rows() == 0)
			{
			return FALSE;
			}
			else
			{
				return TRUE;
			}
	}
	
	
	function create_payment($data_payment)
	{

    $this->db->insert($this->table_name, $data_payment);
	return NULL;
	}

	/**
	 * Activate user if activation key is valid.
	 * Can be called for not activated users only.
	 *
	 * @param	int
	 * @param	string
	 * @param	bool
	 * @return	bool

	/**
	 * Ban user
	 *
	 * @param	int
	 * @param	string
	 * @return	void
	 */

	function get_delegate_payment()
	{
		
		$match = $this->input->post('transaction_num');
		$this->db->select('*');
		$this->db->from('payment');
		$this->db->where('transaction_num', $match);
		$this->db->join('users', 'users_id = id');
		
		$query = $this->db->get();
		return $query->result();
		
	
	}

	
}

